# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest
        
class Task_Lottery(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))
        btnMoreMission = poco("more_mission")
        if btnMoreMission.exists():
            self.clickButton(btnMoreMission)

        try:
            poco("MissionCenterLayer").wait_for_appearance()
        except:
            assert_equal(False, True, "任务中心正常弹出")
            return False

        missionCenterLayer = poco("MissionCenterLayer")
        titleBar = missionCenterLayer.offspring("titile_bar")

        # 打开兑换中心
        btnOpenTip = titleBar.offspring("open_tip")
        self.clickButton(btnOpenTip)

        try: 
            poco("ExchangeCenterLayer").wait_for_appearance()
        except:
            assert_equal(False, True, "兑换中心正常打开")
            return False

        exchangeCenterLayer= poco("ExchangeCenterLayer")
        btnLottery = exchangeCenterLayer.offspring("choujiang_btn")
        if not btnLottery.exists():
            return False

        self.clickButton(btnLottery)

        lotteryLayer = exchangeCenterLayer.offspring("LotteryLayer")
        btnRun = lotteryLayer.offspring("run_btn")
        if btnRun.exists():
            self.clickButton(btnRun)

            lessTipsFrame = lotteryLayer.offspring("less_tips_frame")
            if lessTipsFrame.exists():
                btnClose = lessTipsFrame.offspring("less_tips_close_btn")
                self.clickButton(btnClose)

            acquireTipsFrame = lotteryLayer.offspring("acquire_tips_frame")
            if acquireTipsFrame.exists():
                btnClose = lessTipsFrame.offspring("acquire_tips_btn")
                self.clickButton(btnClose)

            btnClose = lotteryLayer.offspring("close_btn")
            self.clickButton(btnClose)
        
        btnClose = exchangeCenterLayer.offspring("back")
        self.clickButton(btnClose)
        
        btnClose = titleBar.offspring("back")
        self.clickButton(btnClose)

        return True
        
_instance = Task_Lottery()
runTest = _instance.runTest